package com.czk.gulimall.seckill.controller;

import com.czk.common.utils.R;
import com.czk.gulimall.seckill.service.SeckillService;
import com.czk.gulimall.seckill.to.SeckillSkuRedisTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/6/20 22:37
 */
@RestController
public class SeckillController {
    @Autowired
    private SeckillService seckillService;

    @GetMapping("/currentSeckillSkus")
    public R getCurrentSeckillSkus() {
        List<SeckillSkuRedisTo>  list=seckillService.getCurrentSeckillSkus();
        return R.ok().setData(list);
    }

    @GetMapping("/kill")
    public R seckill(@RequestParam("killId") String killId,
                     @RequestParam("key") String key,
                     @RequestParam("num") Integer num){
        String orderNum=seckillService.kill(killId,key,num);
        return R.ok().setData(orderNum);
    }
}
